package com.example.wendao.view.ui.fragment;

import android.os.Bundle;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.wendao.R;
import com.example.wendao.databinding.FragmentTalkContentBinding;
import com.example.wendao.view.adapter.TalkAdapter;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class TalkContentFragment extends Fragment {

    public TalkContentFragment() {}

    private FragmentTalkContentBinding binding;

    private ViewPager2 vp;

    private TabLayout tb;

    private TalkAdapter talkAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_talk_content, container, false);

        talkAdapter = new TalkAdapter(this);
        vp = binding.newsViewPager;
        tb = binding.newTabs;
        vp.setAdapter(talkAdapter);

        new TabLayoutMediator(tb, vp,
                (tab, position) -> {
                    tab.setText(getTabTitle(position));
                }).attach();

        return binding.getRoot();
    }

    private List<String> titles = new ArrayList<>();

    {
        Collections.addAll(titles, "全部", "美食", "时尚", "趣事", "音乐", "健身", "自定义");
    }

    private String getTabTitle(int position) {
        return titles.get(position);
    }

}

